<?php include('scripts.php'); ?>

<script type="text/javascript" language="javascript">
var usdToMyr = ""<?php //echo $usdToMyr;?>;
<!--var handlingCharge = --><?php //echo $handlingCharge;?><!--;-->
<!--var handlingChargeInUsd = --><?php //echo $handlingChargeInUsd;?><!--;-->
$(function() {
    $("#paymentType").change(function() {
        /*if ($(this).val() == "BANK") {
            $(".bankDisplay").show();
        } else {
            $(".bankDisplay").hide();
        }*/
        $("#cbo_mt4Amount").change();
    }).trigger("change");

    $("#cbo_mt4Amount").change(function() {
        var mt4Final = $("#cbo_mt4Amount").val() - 50;
        var handlingCharge = $("#cbo_mt4Amount").val() * 0.95;

        if (parseFloat(handlingCharge) < mt4Final)
            mt4Final = handlingCharge;

        $("#mt4Final").autoNumericSet(mt4Final);
    }).trigger("change");

    $("#withdrawForm").validate({
        messages : {
            transactionPassword: {
                remote: "Security Password is not valid."
            }
        },
        rules : {
            "transactionPassword" : {
                required : true
                , remote: "/member/verifyTransactionPassword"
            }
        },
        submitHandler: function(form) {
            if ($("#mt4Id").val() == "") {
                alert("MT4 status is pending.");
                return false;
            }
            waiting();

            form.submit();
        }
    });
});
</script>

<div id="sub_title" class="highlight"><span class="taller red"></span>

    <p style="font-size: 16px; font-weight: bold;"><?php echo __('MT4 Withdrawal') ?></p></div>

<table cellpadding="0" cellspacing="0">
    <tr>
        <td width="15px" style="min-height: 600px;">&nbsp;</td>
        <td>

<table cellpadding="0" cellspacing="0">
    <tbody>
    <tr>
        <td><br></td>
    </tr>
    <tr>
        <td><br>
            <?php if ($sf_flash->has('successMsg')): ?>
                <div class="ui-widget">
                    <div style="margin-top: 10px; margin-bottom: 10px; padding: 0 .7em;"
                         class="ui-state-highlight ui-corner-all">
                        <p style="margin: 10px"><span style="float: left; margin-right: .3em;"
                                                      class="ui-icon ui-icon-info"></span>
                            <strong><?php echo $sf_flash->get('successMsg') ?></strong></p>
                    </div>
                </div>
                <?php endif; ?>
            <?php if ($sf_flash->has('errorMsg')): ?>
                <div class="ui-widget">
                    <div style="margin-top: 10px; margin-bottom: 10px; padding: 0 .7em;"
                         class="ui-state-error ui-corner-all">
                        <p style="margin: 10px"><span style="float: left; margin-right: .3em;"
                                                      class="ui-icon ui-icon-alert"></span>
                            <strong><?php echo $sf_flash->get('errorMsg') ?></strong></p>
                    </div>
                </div>
                <?php endif; ?>

        </td>
    </tr>
    <tr>
        <td>
            <form action="/member/mt4Withdrawal" id="withdrawForm" name="withdrawForm" method="post">
            <table cellspacing="0" cellpadding="0" class="tbl_form">
                <colgroup>
                    <col width="1%">
                    <col width="30%">
                    <col width="69%">
                    <col width="1%">
                </colgroup>
                <tbody>
                <tr>
                    <th class="tbl_header_left">
                        <div class="border_left_grey">&nbsp;</div>
                    </th>
                    <th colspan="2"><?php echo __('MT4 Withdrawal') ?></th>
<!--                    <th class="tbl_content_right"></th>-->
                    <th class="tbl_header_right">
                        <div class="border_right_grey">&nbsp;</div>
                    </th>
                </tr>

                <tr class="tbl_form_row_odd">
                    <td>&nbsp;</td>
                    <td><?php echo __('MT4 ID'); ?></td>
                    <td>
                        <!--<select name="mt4Id" id="mt4Id" tabindex="1">
                            <?php
/*                                if (count($distMt4DBs) >= 1) {
                                    foreach ($distMt4DBs as $distMt4DB) {
                                        echo "<option value='".$distMt4DB->getMt4UserName()."'>".$distMt4DB->getMt4UserName()."</option>";
                                    }
                                } else {
                                    echo "<option value=''>--</option>";
                                }
                            */?>
                        </select>-->
                        <input name="mt4Id" id="mt4Id" disabled="disabled" value="<?php echo $distributorDB->getMt4UserName(); ?>"/>
                    </td>
                    <td>&nbsp;</td>
                </tr>

                <tr class="tbl_form_row_even" style="display: none;">
                    <td>&nbsp;</td>
                    <td><?php echo __('Payment Type'); ?></td>
                    <td>
                        <select name="paymentType" id="paymentType">
                            <option value='VISA'>VISA Cash Card</option>
                            <option value='BANK'>Local Bank Transfer</option>
                        </select>
                    </td>
                    <td>&nbsp;</td>
                </tr>

                <tr class="tbl_form_row_even">
                    <td>&nbsp;</td>
                    <td><?php echo __('MT4 Fund Withdrawal Amount In RMB'); ?></td>
                    <td>
                        <select name="mt4Amount" id="cbo_mt4Amount">
                            <?php
                                //if ($distributorDB->getMt4UserName() != null) {
                                for ($i = 100; $i <= 10000; $i = $i + 100) {
                                    echo "<option value='".$i."'>".number_format($i, 0)."</option>";
                                }
                                for ($i = 20000; $i <= 50000; $i = $i + 10000) {
                                    echo "<option value='".$i."'>".number_format($i, 0)."</option>";
                                }
                                //}
                            ?>
                        </select>
                    </td>
                    <td>&nbsp;</td>
                </tr>

                <tr class="tbl_form_row_odd">
                    <td>&nbsp;</td>
                    <td>
                        <?php echo __('After handling fee'); ?>
                    </td>
                    <td>
                        <input name="mt4Final" type="text" id="mt4Final" readonly="readonly" tabindex="3"/>
                    </td>
                    <td>&nbsp;</td>
                </tr>

                <tr class="tbl_form_row_even"  style="display: none;">
                    <td>&nbsp;</td>
                    <td><?php echo __('RMB convert to MYR ').$usdToMyr; ?></td>
                    <td>
                        <input name="myrCurrency" id="myrCurrency" disabled="disabled" value=""/>
                        <span class="currencyCode"></span>
                    </td>
                    <td>&nbsp;</td>
                </tr>

                <tr class="tbl_form_row_odd" style="display: none;">
                    <td>&nbsp;</td>
                    <td>
                        <?php echo __('Bank Charges') ?>
                    </td>
                    <td>
                        <input name="handlingFee" id="handlingFee" disabled="disabled" value=""/>
                        <span class="currencyCode"></span>
                    </td>
                    <td>&nbsp;</td>
                </tr>
                <tr class="tbl_form_row_even" style="display: none;">
                    <td>&nbsp;</td>
                    <td>
                        <?php echo __('Grand Amount') ?>
                    </td>
                    <td>
                        <input name="grandAmount" id="grandAmount" disabled="disabled" value=""/>
                        <span class="currencyCode"></span>
                    </td>
                    <td>&nbsp;</td>
                </tr>
                <tr class="tbl_form_row_even">
                    <td>&nbsp;</td>
                    <td>
                        <?php echo __('Security Password'); ?>
                    </td>
                    <td>
                        <input name="transactionPassword" type="password" id="transactionPassword"/>
                    </td>
                    <td>&nbsp;</td>
                </tr>

                <tr class="tbl_form_row_odd">
                    <td>&nbsp;</td>
                    <td colspan="1" align="right" valign="top">
                        <font color="#dc143c"> <?php echo __('NOTE :') ?></font> &nbsp;
                    </td>
                    <td colspan="1" align="left">
                        <font color="#dc143c"> <?php echo __('1. Minimum withdrawal amount : RMB 100
                        <br>2. Withdrawal Amount will be credited to e-Wallet.
                        <br>3. Handling fee RMB50 or 5% whichever is higher
                        <br>4. Processing time : 5 working days') ?></font>
                    </td>
                    <td>&nbsp;</td>
                </tr>

                <tr class="tbl_form_row_odd">
                    <td>&nbsp;</td>
                    <td></td>
                    <td align="right">
                        <button id="btnTransfer"><?php echo __('Submit') ?></button>
                    </td>
                    <td>&nbsp;</td>
                </tr>
                </tbody>
            </table>

            </form>

            <div class="info_bottom_bg"></div>
            <div class="clear"></div>
            <br>

            <script type="text/javascript" language="javascript">
            var datagrid = null;
            $(function() {
                datagrid = $("#datagrid").r9jasonDataTable({
                    // online1DataTable extra params
                    "idTr" : true, // assign <tr id='xxx'> from 1st columns array(aoColumns);
                    "extraParam" : function(aoData) { // pass extra params to server
                    },
                    "reassignEvent" : function() { // extra function for reassignEvent when JSON is back from server
                        reassignDatagridEventAttr();
                    },

                    // datatables params
                    "bLengthChange": true,
                    "bFilter": false,
                    "bProcessing": true,
                    "bServerSide": true,
                    "bAutoWidth": false,
                    "sAjaxSource": "/finance/mt4WithdrawalList",
                    "sPaginationType": "full_numbers",
                    "aaSorting": [
                        [2,'desc']
                    ],
                    "aoColumns": [
                        { "sName" : "dist_id", "bVisible" : false,  "bSortable": true},
                        { "sName" : "currency_code", "bVisible" : false,  "bSortable": true},
                        { "sName" : "created_on",  "bSortable": true},
                        { "sName" : "amount_requested",  "bSortable": true},
                        { "sName" : "handling_fee",  "bSortable": false},
                        { "sName" : "grand_amount",  "bSortable": false},
                        { "sName" : "payment_type",  "bVisible": false},
                        { "sName" : "status_code",  "bSortable": true},
                        { "sName" : "remarks",  "bSortable": true}
                    ]
                });
            }); // end function

            function reassignDatagridEventAttr() {
            }
        </script>

        <table cellspacing="0" cellpadding="0" class="tbl_form">
            <colgroup>
                <col width="1%">
                <col width="30%">
                <col width="69%">
                <col width="1%">
            </colgroup>
            <tbody>
            <tr>
                <th class="tbl_header_left">
                    <div class="border_left_grey">&nbsp;</div>
                </th>
                <th><?php echo __('MT4 Withdrawal Status') ?></th>
                <th class="tbl_content_right"></th>
                <th class="tbl_header_right">
                    <div class="border_right_grey">&nbsp;</div>
                </th>
            </tr>
            </tbody>
        </table>
        <br>
        <table class="display" id="datagrid" border="0" width="100%">
            <thead>
            <tr>
                <th></th>
                <th><?php echo __('Currency Code') ?></th>
                <th><?php echo __('Date') ?></th>
                <th><?php echo __('Amount Requested (RMB)') ?></th>
                <th><?php echo __('Bank Charges (RMB)') ?></th>
                <th><?php echo __('Grand Amount (RMB)') ?></th>
                <th><?php echo __('Payment Type') ?></th>
                <th><?php echo __('Status') ?></th>
                <th><?php echo __('Remarks') ?></th>
            </tr>
            </thead>
        </table>
        </td>
    </tr>
    </tbody>
</table>
<td width="15px">&nbsp;</td>
    </tr>
</table>